package cn.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import cn.domain.User;

/**
 * 
 * @项目名称:pigbaby
 * @类名称:ApkAction
 * @类描述:移动设备的所有接口
 * @创建人:陈凯
 * @创建时间:20150713 17：23 星期一
 * @修改人:
 * @修改时间:
 * 
 * @修改备注:
 * @version
 */
@Namespace("/")
@Scope("prototype")
@ParentPackage("json-default")
@Component("loginAction")
@Action(value = "loginAction", results = { 
		@Result(name = "loginout", location = "/login.jsp"),
		@Result(name = "index", location = "/index.jsp"),
		@Result(name = "resultjson", type = "json")
		})
public class LoginAction extends BaseAction {

	// 保存日志
	public static Logger logger = LoggerFactory.getLogger(LoginAction.class);
	
	private User user;
	
	public String chkname(){
		User temp = userService.getOne(user);
		if(temp != null && temp.getId() != null){
			request.getSession().setAttribute("user", temp);
			outJSONMessage("success");
		}else{
			outJSONMessage("用户名或者密码错误！");
		}
		return "resultjson";
	}
	
	public String loginOut(){
		request.getSession().removeAttribute("user");
		return "loginout";
	}
	public String index(){
		return "index";
	}
	
	public String loginout(){
		return "loginout";
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	
}
